<?php
/**
 * FormError.php
 * 
 * @category   Naneau
 * @package    Naneau_View_Helper
 * @copyright  Copyright (c) 2007 Maurice Fonk - http://naneau.nl
 * @version    0.1
 */

/**
 * Naneau_View_Helper_FormError
 * 
 * a helper to output simple error messages after form validation fails
 *
 * @category   Naneau
 * @package    Naneau_View_Helper
 * @copyright  Copyright (c) 2007 Maurice Fonk - http://naneau.nl
 */
class Naneau_View_Helper_FormError {

    /**
     * check if a error is set in $errors and return in wrapped in a paragraph
     * and unordered list
     * 
     * @param string $field
     * @param arrat $errors
     * @return string
     */
    public function formError($field, $errors) {
        if (isset($errors[$field])) {
            //there is at least one error for $field
            $html = '<p class="error">';
            $html .= '<ul>';
            foreach ($errors[$field] as $errorMessage) {
                //for every error message for $field
                $html .= '<li>' . $errorMessage . '</li>';
            }
            $html .= '</ul></p>';
            return $html;
        }
    }
}